package com.xxb.system.feign.callback;

import com.xxb.common.exception.SystemErrorEnum;
import com.xxb.common.result.R;
import com.xxb.system.feign.dto.user.*;
import com.xxb.system.feign.service.user.UserServiceFeign;
import feign.hystrix.FallbackFactory;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

/**
 * @author RenGaoshuai
 * @date 2023/7/27 16:18
 * @description 熔断类
 */
@Service
@Slf4j
public class UserServiceFallBackFactory implements FallbackFactory<UserServiceFeign> {


    @Override
    public UserServiceFeign create(Throwable throwable) {
        // 打印一下
        throwable.printStackTrace();
        // 输出日志,方便后面进行elk
        log.error("UserServiceFeign error:", throwable);

        return new UserServiceFeign() {
            @Override
            public R<LoginRespFeignDTO> login(LoginReqFeignDTO dto) {
                return R.ofFail(SystemErrorEnum.CALLBACK_ERROR_MESSAGE);
            }

            @Override
            public R<String> updateUserTel(LoginTelReqFeignDTO dto) {
                return R.ofFail(SystemErrorEnum.CALLBACK_ERROR_MESSAGE);
            }

            @Override
            public R<String> createUserFaceModel(LoginCreateFaceReqFeignDTO dto) {
                return R.ofFail(SystemErrorEnum.CALLBACK_ERROR_MESSAGE);
            }

            @Override
            public R<String> verifyUserFaceModel(LoginVerifyFaceReqFeignDTO dto) {
                return R.ofFail(SystemErrorEnum.CALLBACK_ERROR_MESSAGE);
            }

            @Override
            public R<String> updateUserModel(UpdateUserReqFeignDTO dto) {
                return R.ofFail(SystemErrorEnum.CALLBACK_ERROR_MESSAGE);
            }

            @Override
            public R<QueryUserRespFeignDTO> queryUserInfo(QueryUserReqFeignDTO dto) {
                return R.ofFail(SystemErrorEnum.CALLBACK_ERROR_MESSAGE);
            }

            @Override
            public R getUserInfo(Long userId) {
                return R.ofFail(SystemErrorEnum.CALLBACK_ERROR_MESSAGE);
            }
        };
    }
}
